﻿Imports System.Data.SqlClient
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
Public Class 网络代码
    Dim cnStr As String = System.Text.Encoding.Default.GetString(System.Convert.FromBase64String("ZGF0YSBzb3VyY2U9MS4xNS4xNTMuMTMxO2luaXRpYWwgY2F0YWxvZz1WQkHEo7/pO3VzZXIgaWQ9VkJBxKO/6bfDzso7cGFzc3dvcmQ9OGs3blczWmZBO2FwcGxpY2F0aW9uIG5hbWU9UE5ldFNWaWV3"))
    Dim cn As SqlConnection
    Dim da As SqlDataAdapter
    Dim ds As DataSet
    Dim id As String

    <DllImport("user32.dll", EntryPoint:="FindWindowA", CharSet:=CharSet.Ansi)>
    Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As Integer

    End Function
    <DllImport("user32.dll", EntryPoint:="GetWindowText")>
    Public Shared Function GetWindowText(ByVal hwnd As Integer, ByVal lpString As StringBuilder, ByVal cch As Integer) As Integer

    End Function
    <DllImport("user32.dll", EntryPoint:="GetWindow")>
    Public Shared Function GetWindow(ByVal hwnd As Integer, ByVal wCmd As Integer) As Integer

    End Function
    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
    Public Shared Function GetClassName(ByVal hWnd As Integer, ByVal lpClassName As StringBuilder, ByVal nMaxCount As Integer) As Integer

    End Function
    Sub 获取qq()
        Dim hWin As Integer = FindWindow("CTXOPConntion_Class", Nothing)

        If hWin = 0 Then
            Return
        End If

        Dim sbf As StringBuilder = New StringBuilder(256)
        Dim sbfClass As StringBuilder = New StringBuilder(256)

        While hWin > 0
            GetWindowText(hWin, sbf, sbf.Capacity)

            If sbf.ToString().Contains("OP_") Then
                id = sbf.ToString()
            End If

            Do
                hWin = GetWindow(hWin, 2)

                If hWin = 0 Then
                    Exit Do
                End If

                GetClassName(hWin, sbfClass, sbfClass.Capacity)
            Loop While "CTXOPConntion_Class".Equals(sbfClass)
        End While
    End Sub
    Sub 链接()

        cn = New SqlConnection(cnStr)
        da = New SqlDataAdapter("select * from MK", cn)
        ds = New DataSet()
        da.Fill(ds, "MK")
        DataGridView1.DataSource = ds.Tables("MK")
    End Sub
    Sub 保存()
        Dim a As String = Me.模块名称.Text
        Dim b As String = Replace(Me.模块代码.Text, "'", "''")
        'b = Replace(b, "", ": Rem")
        Dim c As String = Me.上传者.Text
        Dim d As String = Now

        Try
            cn = New SqlConnection(cnStr)
            da = New SqlDataAdapter("insert into  MK (模块名称,模块代码,上传者,上传日期)  values('" & a & "','" & b & "','" & c & "','" & d & "') ", cn)
            ds = New DataSet()
            da.Fill(ds, "MK")
            DataGridView1.DataSource = ds.Tables("MK")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

        链接()
    End Sub
    Private Sub 网络代码_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        获取qq()
        If id <> "" Then
            Me.上传者.Text = id
            'Me.上传者.ReadOnly = True
        Else
            Me.上传者.Text = "未知姓名"
            'Me.上传者.ReadOnly = True
        End If


        链接()
    End Sub



    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        保存()
        链接()
    End Sub



    Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Dim 选中 As String = DataGridView1.CurrentRow.Cells(1).Value
        Me.模块代码.Text = 选中
    End Sub

    Private Sub 模块代码_TextChanged(sender As Object, e As EventArgs)

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Try
            If FontDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
                Me.模块代码.ForeColor = FontDialog1.Color
                Me.模块代码.Font = FontDialog1.Font
            End If '原文出自【易百教程】，商业转载请联系作者获得授权，非商业请保留原文链接：https : //yiibai.com/vb.net/vb.net_font_dialog.html
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    End Sub
End Class